package com.study.ming.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author yh
 * @date 2022/10/15 20:38
 **/
@RestController
@RefreshScope
public class HelloController {

    RestTemplate restTemplate;

    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    public HelloController(RestTemplate restTemplate) {this.restTemplate = restTemplate;}

    @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
    public String echo(@PathVariable String str) {
        List<String> services = discoveryClient.getServices();
        System.out.println(services);
        ResponseEntity<String> entity = restTemplate.getForEntity("http://nacos_config/echo2/" + str, String.class);
        return entity.getBody();
    }
    @RequestMapping(value = "/echo2/{str}", method = RequestMethod.GET)
    public String echo2(@PathVariable String str) {
        return str+"this is from nacosconfig echo2";
    }
}
